<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<div id="cc" class="easyui-calendar" style="width: 100%; height: 100%;">
	
	</div>
	<!-- 弹出新增窗口代码开始 1231231-->
	<div id="ddcalendar" class="easyui-dialog"
		style="width:70%; height: 400px"
		data-options="modal:true,closed:true,title:'行政日历'">
	  <div id="huodg1" >
	        <a id="addcalendar" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true">添加</a>
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" Onclick="removecalendar()" >删除</a>
			<a id="editcc" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" Onclick="editcc()">编辑</a>
	   日期从:    <input id="begin" class="easyui-datebox">
	          到:    <input id="end" class="easyui-datebox">
	        <sapn>搜索文本：</sapn><input class="easyui-searchbox " style="width:200px" data-options="searcher:searchname,prompt:'请输入需要搜索的名称'"></input>
	  </div>
	  <table id="huo_dgcc" class="easyui-datagrid"></table>
	  <script src="../hyn/js/check/calendar.js"></script>
	</div>
	
	<!-- 弹出新增窗口代码结束 -->
	
	<!-- 弹出新增窗口代码开始 -->
	<div id="huoddc" class="easyui-dialog" style="width:50%; height: 300px"
		data-options="modal:true,closed:true,title:'添加假种信息'">
		<form id="ff" method="post" action="addemp">
			<div id="holidaybody" style="margin: 2% 10%">
			<input class="easyui-textbox " type="hidden" id="calendarId"/>
			<div>开始日期:<input id="beginTime" class="easyui-datebox holidaytext"></div>  
			<div>结束日期:<input id="endTime" class="easyui-datebox holidaytext"><br></div>
			    <label>主&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp题:</label> 
				<input  id="theam" class="easyui-textbox holidaytext" />
				<label>备&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp注:</label> 
				<input  id="remark" class="easyui-textbox holidaytext" /><br>
			    <label>种&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp类:</label> 
				<input  id="holidayId" class="easyui-combobox holidaytext" />
				<label>事务类型:</label> 
				<input  id="affairId" class="easyui-combobox holidaytext"/>
			</div>
		</form>
	</div>
	<script type="text/javascript">
		$("#beginTime").datebox({
			
		})
		$("#endTime").datebox({
			
		})
		$("#holidayId").combobox({
					url:'../check/getholidaykind2',
					valueField:'holidayId',
					textField:'holidayName',
					panelHeight:'auto'
		});
		$("#affairId").combobox({
					url:'../check/getcheckAffairCategory2',
					valueField:'affairId',
					textField:'affairName',
					panelHeight:'auto'
		});
		$("#addcalendar").linkbutton({
			onClick : function() {
				$("#huoddc").window("open");
			}
		});
		// 定义底部保存，清空，取消按钮
		$('#huoddc').dialog({
			buttons : [ {
				text : '保存',
				iconCls : 'icon-save',
				handler : function() {
					$('#ff').form('submit', {
						onSubmit : function(param) {
							var calendarId= $("#calendarId").val();
							var affairBegintime = $("#beginTime").val();
							var affairEndtime =$("#endTime").val();
							var theam =$("#theam").val();
							var remark=$("#remark").val();
							var holidayId = $("#holidayId").val();
							var affairId=$("#affairId").val();
							var calendars = [];
							if(calendarId==null||calendarId===''){
								var calendar = {
										affairBegintime : affairEndtime,
										affairEndtime : affairEndtime,
										theam:theam,
										remark:remark,
										affairId:affairId,
										holidayId : holidayId
									};
								    calendars.push(calendar);
									var jsondata = JSON.stringify(calendars);
									alert(jsondata);
								$.ajax({
									url : "../check/addcalendarAffair",
									data : {"jsondata" : jsondata},
									success : function(e) {
										if (e == "ok") {
											alert("存储成功");
			                               $('#huo_dgcc').datagrid('load');
										}
									}
								});
							}
							else{
								var calendar = {
										calendarId:calendarId,
										affairBegintime : affairBegintime,
										affairEndtime : affairEndtime,
										theam : theam,
										remark:remark,
										affairId:affairId,
										holidayId : holidayId
									};
								   calendars.push(calendar);
									var update_jsondata = JSON.stringify(calendars);
								$.ajax({
									url : "../check/updatecalendarAffair",
									data : {"update_jsondata" :update_jsondata},
									success : function(e) {
										if (e == "ok") {
											alert("修改成功");
			                               $('#huo_dgcc').datagrid('load');
										}
									}
								});
							}
						},
						success : function(data) {

						}
					});
				}
			}, {
				text : '清空',
				iconCls : 'icon-clear',
				handler : function() {
					$('#ff').form('clear');
				}
			}, {
				text : '取消',
				iconCls : 'icon-cancel',
				handler : function() {
					$("#huoddc").window("close");
				}
			} ]
		});
	    var editIndex = undefined;
		function removecalendar(){
			if (editIndex == undefined){
				var rows = $('#huo_dgcc').datagrid('getSelections');
				if(rows.length > 0){
					$.messager.confirm('请确认','您确定要删除当前所有选中的项目吗？',function(r){
						if(r){
							var holidayIds = [];
							for(var i = 0; i < rows.length; i++){
								holidayIds.push(rows[i].calendarId)
							}
							var huo_rowData = JSON.stringify(holidayIds);
							alert(huo_rowData);
							$.ajax({
								url : "../check/deletecalendarAffair",
								data : {"huo_rowData" : huo_rowData},
								success : function(e) {
									if (e == "ok") {
		                               alert("删除成功");
		                               $('#huo_dgcc').datagrid('load');
									}
								}
							});
						}
					 })
					}
			}
			$('#huo_dgcc').datagrid('cancelEdit', editIndex).datagrid('deleteRow', editIndex);
			editIndex = undefined;
		}
		function searchname(value){
			var begin = $("#begin").val();
			var end =$("#end").val();
			 $('#huo_dgcc').datagrid('load','../check/serchcalendar?begin='+begin+'&end='+end+'&affairName='+value);
		} 
		function editcc(){
				var rows = $('#huo_dgcc').datagrid('getSelected');
				if(rows.calendarId!=null||rows.calendarId==""){
					$("#calendarId").val(rows.calendarId);
					$("#affairBegintime").val(rows.affairBegintime);
					$("#affairEndtime").val(rows.affairEndtime);
					$("#theam").val(rows.theam);
					$("#remark").val(rows.remark);
					$("#holidayId").val(rows.checkHolidayKind.holidayName);
					$("#affairId").val(rows.checkAffariCategory.affairName);
					$("#huoddc").window("open");
				}else{
					alert("未勾选数据");
				}
		}
	</script>
	<!-- 弹出新增窗口代码结束 -->
</body>
</html>